package org.fight.landowner.common.serialize;

/**
 * @Author wangxuehao02
 * @Date 2024/2/8 4:16 PM
 * @Description
 **/
public class BytesSerializableFactory {
    private static BytesSerializer jsonSerializer = new BytesJSONSerializer();

    public static byte[] serialize(Object data, SerializableType serializableType) {
        switch (serializableType) {
            case JSON: {
                return jsonSerializer.serialize(data);
            }
            default: {
                return null;
            }
        }
    }

    public static <T> T deSerialize(byte[] data, Class<T> clazz, SerializableType serializableType) {
        if (data == null || data.length == 0) {
            return null;
        }

        switch (serializableType) {
            case JSON: {
                return jsonSerializer.deSerialize(data, clazz);
            }
            default: {
                return null;
            }
        }
    }
}
